package com.bluedot.web.actions;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

public class DateConertor extends StrutsTypeConverter  {

	
	public Object convertFromString(Map maps, String[] values, Class classes) {
		if(values!=null&&values.length>0&&values[0].length()>0&&values[0]!=null){
		SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
		try {
			return sim.parse(values[0]);
		} catch (ParseException e) {
		
			e.printStackTrace();
		} 
		
		}
		return null;
	}


	public String convertToString(Map map, Object obj) {
		if(obj instanceof Date)
		{
			SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
			return sim.format((Date)obj);
		}
		return "";
	}

}
